<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
          label-width="68px">
          <el-form-item label="" prop="unitname">
            <el-input v-model="queryParams.phone" placeholder="联系人昵称/电话" clearable style="width: 240px"
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="" prop="status">
            <el-select v-model="queryParams.status" placeholder="单位会员等级" clearable style="width: 240px">
              <el-option v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.label"
                :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport"
              v-hasPermi="['system:user:import']">导入</el-button>
            <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
              v-hasPermi="['system:user:export']">导出</el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getnormalMemberList"></right-toolbar>
      <div>
      </div>
    </el-row>
    <el-row>
      <splitpanes :horizontal="this.$store.getters.device === 'mobile'" class="default-theme">
        <!--单位会员数据-->
        <pane size="84">
          <el-col>
            <el-table v-loading="loading" :data="normalMemberList" @selection-change="">
              <el-table-column type="selection" width="50" align="center" />
              <el-table-column label="用户名" align="center" key="name" prop="name" />
              <el-table-column label="昵称" align="center" key="nickname" prop="nickname" :show-overflow-tooltip="true" />
              <el-table-column label="电子邮箱" align="center" key="email" prop="email" :show-overflow-tooltip="true" />
              <el-table-column label="手机号" align="center" key="phone" prop="phone" :show-overflow-tooltip="true" />
              <el-table-column label="头像" align="center" key="avatar" prop="avatar" width="120" />
              <el-table-column label="登录时间" align="center" key="login_time" prop="login_time" />
              <el-table-column label="登录IP" align="center" key="login_ip" prop="login_ip" />
              <el-table-column label="加入时间" align="center" prop="join_time" width="160">
              </el-table-column>
              <el-table-column label="加入IP" align="center" key="join_ip" prop="join_ip" />
              <el-table-column label="状态" align="center" key="status" prop="status">
                <template slot-scope="scope">
                  <div class="status" :class="{ 'status-success': scope.row.status == 1, 'success': 'danger' }">
                    <div class="point"></div>
                    {{ scope.row.status == 1 ? "正常" : "冻结" }}

                  </div>
                </template>
              </el-table-column>
              <!-- <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
                <template slot-scope="scope" v-if="scope.row.userId !== 1">
                  <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                    v-hasPermi="['member:edit']">修改</el-button>
                  <el-button size="mini" type="text" icon="el-icon-edit" @click="handleDelete(scope.row)"
                    v-hasPermi="['member:edit']">删除</el-button>
                </template>
              </el-table-column> -->
            </el-table>
            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
              :limit.sync="queryParams.pageSize" @pagination="" />
          </el-col>
        </pane>
      </splitpanes>
    </el-row>
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的普通会员数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline"
            @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { Splitpanes, Pane } from "splitpanes";
import "splitpanes/dist/splitpanes.css";
import { listnormalMember } from "@/api/member/member";
import { getToken } from "@/utils/auth";
export default {
  name: "member",
  dicts: [],
  components: { Treeselect, Splitpanes, Pane },
  data() {
    return {
      // 普通会员单位导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的会员单位数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/member/normalimportData"
      },
      // 显示搜索条件
      showSearch: true,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 普通会员表格数据
      normalMemberList: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        phone: undefined,
      },
    }
  },
  methods: {
    /** 查询普通会员列表 */
    getnormalMemberList() {
      this.loading = true;
      listnormalMember(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.normalMemberList = response.rows;
        this.total = response.total;
        this.loading = false;
      }
      );
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryParams");
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getnormalMemberList();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/member/normalexport', {
        ...this.queryParams
      }, `普通会员导出数据${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "普通会员导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('/member/normalimportData', {
      }, `普通会员模板数据${new Date().getTime()}.xlsx`)
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getnormalMemberList();
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
  },
  created() {
    this.getnormalMemberList();
  },
}
</script>

<style lang="scss" scoped>
.status {
  display: flex;
  align-items: center;
  justify-content: center;

  &.danger {
    color: #f00;

    .point {
      background-color: #f00;
    }
  }

  &.success {
    color: #0f0;

    .point {
      background-color: #0f0;
    }
  }

  .point {
    width: 8px;
    height: 8px;
    border-radius: 8px;
    margin-left: 4px;
  }
}
</style>